package zoo.workers;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import zoo.animals.Animal;
import zoo.food.Food;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: platonovv
 * Date: 25.11.13
 * To change this template use File | Settings | File Templates.
 */
public class Feeder extends Worker {
    private static final Log log = LogFactory.getLog(Worker.class);
    private List<Animal> animals = new ArrayList();

    public Feeder(String name) {
        super(name);
    }

    public void add(Animal animal) {
        animals.add(animal);
    }

    public void voice() {
        log.info("Hello from feeder " + getName());
    }

    public void feed() {
        for (Animal animal : animals) {
            try {
                animal.feed(new Food());
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}
